﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Business.Cdc
{
    public class FileDb : IComparable
    {
        private int id;
        public int Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }
        
        private DateTime date, _date;
        public DateTime Date
        {
            get
            {
                return date;
            }
            set
            {
                date = value;
            }
        }

        private String subject, _subject;
        public String Subject
        {
            get
            {
                return subject;
            }
            set
            {
                subject = value;
            }
        }

        private DateTime importDate;
        public DateTime ImportDate
        {
            get
            {
                return importDate;
            }
            set
            {
                importDate = value;
            }
        }

        private String title,_title;
        public String Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }

        private int fileSize;
        public int FileSize
        {
            get
            {
                return fileSize;
            }
            set
            {
                this.fileSize = value;
            }
        }

        private Boolean reported, _reported;
        public Boolean Reported
        {
            get
            {
                return reported;
            }
            set
            {
                this.reported = value;
            }
        }

        public FileDb(int _id,
            int _fileSize,
            DateTime _date,
            DateTime _importDate,
            String _title,
            String _subject,
            Boolean _isReported)
        {
            this.id = _id;
            this.fileSize = _fileSize;
            this.date = _date;
            this.importDate = _importDate;
            this.title = _title;
            this.subject = _subject;
            this.reported = _isReported;
            commit();
        }

        public FileDb()
        {
            this.id = -1;
            this.fileSize = 0;
            this.date = DateTime.Parse(DateTime.Now.ToShortDateString());
            this.importDate = DateTime.Parse(DateTime.Now.ToShortDateString());
            this.title = null;
            this.subject = null;
            this.reported = false;
            commit();
        }

        public virtual void commit()
        {
            this._date = this.date;
            this._reported = this.reported;
            this._subject = this.subject;
            this._title = this.title;
        }

        public virtual void reject()
        {
            this.date = this._date;
            this.reported = this._reported;
            this.subject = this._subject;
            this.title = this._title;
        }
        
        public int CompareTo(Object o)
        {
            FileDb c = (FileDb)o;
            int subj1 = 0;
            int subj2 = 0;
            switch (c.subject)
            {
                case "TVA": subj1 = 0; break;
                case "RSI": subj1 = 3; break;
                case "URSSAF": subj1 = 2; break;
                case "CIPAV": subj1 = 4; break;
                case "Facture": subj1 = 5; break;
                case "Portable": subj1 = 6; break;
                case "Internet": subj1 = 7; break;
                case "Repas": subj1 = 8; break;
                case "Transport": subj1 = 9; break;
                case "Others": subj1 = 10; break;
                case "Banque": subj1 = 11; break;
            }
            switch (subject)
            {
                case "TVA": subj2 = 0; break;
                case "RSI": subj2 = 3; break;
                case "URSSAF": subj2 = 2; break;
                case "CIPAV": subj2 = 4; break;
                case "Facture": subj2 = 5; break;
                case "Portable": subj2 = 6; break;
                case "Internet": subj2 = 7; break;
                case "Repas": subj2 = 8; break;
                case "Transport": subj2 = 9; break;
                case "Others": subj2 = 10; break;
                case "Banque": subj2 = 11; break;
            }
            if (subj1 == subj2)
            {
                return DateTime.Compare(date, c.date);
            } else 
            {
                if (subj1 > subj2)
                {
                    return -1;
                }
                else
                {
                    return 1;
                }
            }
        }
    }
 
}
